// Written by Craig'n'Dave
using System;
// Stack using objects
namespace ConsoleApp1
{
    class Program
    {
        public class Stack
        {
            private class Node
            {
                public string data;
                public Node pointer;
            }

            private Node stack_pointer;

            public bool push(string item)
            {
                // Check queue overflow
                try
                {
                    // Push the item
                    Node new_node = new Node();
                    new_node.data = item;
                    new_node.pointer = stack_pointer;
                    stack_pointer = new_node;
                    return true;
                }
                catch
                {
                    return false;
                }
            }

            public string pop()
            {
                // Check stack underflow
                if (stack_pointer != null)
                {
                    // Pop the item
                    string item = stack_pointer.data;
                    stack_pointer = stack_pointer.pointer;
                    return item;
                }
                else
                {
                    return null;
                }
            }

            public string peek()
            {
                // Check stack underflow
                if (stack_pointer != null)
                {
                    // Peek the item
                    return stack_pointer.data;
                }
                else
                {
                    return null;
                }
            }
        }

        // Main program starts here
        static void Main(string[] args)
        {
            string[] items = new string[] { "Florida", "Georgia", "Delaware", "Alabama", "California" };
            Stack s = new Stack();
            // Add items to the stack
            for (int index = 0; index < items.Length; index++)
            {
                s.push(items[index]);
            }
            // Remove items from the stack
            Console.WriteLine(s.pop());
            // Output the next item in the stack
            Console.WriteLine(s.peek());
        }
    }
}
